<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
<<<<<<< HEAD
      <!--      <el-form-item label="楼盘id" prop="buildingId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.buildingId"-->
      <!--          placeholder="请输入楼盘id"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
=======
>>>>>>> origin/master
      <el-form-item label="小区名称" prop="communityName">
        <el-input
          v-model="queryParams.communityName"
          placeholder="请输入小区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<<<<<<< HEAD
      <!--      <el-form-item label="占地面积/m2" prop="floorArea">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.floorArea"-->
      <!--          placeholder="请输入占地面积/m2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="建筑面积/m2" prop="structureArea">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.structureArea"-->
      <!--          placeholder="请输入建筑面积/m2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="绿化面积/m2" prop="greenArea">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.greenArea"-->
      <!--          placeholder="请输入绿化面积/m2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="绿化率/%" prop="greenRate">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.greenRate"-->
      <!--          placeholder="请输入绿化率/%"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="容积率" prop="plotRate">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.plotRate"-->
      <!--          placeholder="请输入容积率"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="规划车位" prop="plannedParking">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.plannedParking"-->
      <!--          placeholder="请输入规划车位"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="车位配比" prop="parkingRatio">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.parkingRatio"-->
      <!--          placeholder="请输入车位配比"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="规划楼栋" prop="plannedBuilding">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.plannedBuilding"-->
      <!--          placeholder="请输入规划楼栋"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
=======

>>>>>>> origin/master
      <el-form-item label="物业公司" prop="propertyCompany">
        <el-input
          v-model="queryParams.propertyCompany"
          placeholder="请输入物业公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<<<<<<< HEAD
      <!--      <el-form-item label="物业费用/元/m2/月元/m2/月" prop="propertyExpenses">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.propertyExpenses"-->
      <!--          placeholder="请输入物业费用/元/m2/月元/m2/月"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
=======

>>>>>>> origin/master
      <el-form-item label="供暖方式" prop="heatingMode">
        <el-select
          v-model="queryParams.heatingMode"
          placeholder="请选择供暖方式"
          clearable
        >
          <el-option
            v-for="dict in dict.type.plot_heating_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="房屋类型" prop="houseType">
        <el-select
          v-model="queryParams.houseType"
          placeholder="请选择房屋类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.plot_houses_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供水" prop="waterMode">
        <el-select
          v-model="queryParams.waterMode"
          placeholder="请选择供水"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_water_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供电" prop="electricMode">
        <el-select
          v-model="queryParams.electricMode"
          placeholder="请选择供电"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_electric_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="燃气" prop="gasMode">
        <el-select
          v-model="queryParams.gasMode"
          placeholder="请选择燃气"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_gas_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="通讯配套齐备" prop="isKit">
        <el-select
          v-model="queryParams.isKit"
          placeholder="请选择通讯配套齐备"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_is_kit"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<<<<<<< HEAD
      <!--      <el-form-item label="小区特点" prop="cellCharacteristics">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.cellCharacteristics"-->
      <!--          placeholder="请输入小区特点"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
=======
      】
>>>>>>> origin/master
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['plot:plot:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['plot:plot:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['plot:plot:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['plot:plot:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="plotList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
<<<<<<< HEAD
      <el-table-column label="小区id" align="center" prop="id" />

      <el-table-column label="楼盘id" align="center" prop="buildingId" />
=======
      <el-table-column label="ID" align="center" prop="id" />
>>>>>>> origin/master
      <el-table-column label="小区名称" align="center" prop="communityName" />
      <el-table-column label="占地面积/m2" align="center" prop="floorArea" />
      <el-table-column
        label="建筑面积/m2"
        align="center"
        prop="structureArea"
      />
      <el-table-column label="绿化面积/m2" align="center" prop="greenArea" />
      <el-table-column label="绿化率/%" align="center" prop="greenRate" />
      <el-table-column label="容积率" align="center" prop="plotRate" />
      <el-table-column label="规划车位" align="center" prop="plannedParking" />
      <el-table-column label="车位配比" align="center" prop="parkingRatio" />
      <el-table-column label="规划楼栋" align="center" prop="plannedBuilding" />
      <el-table-column label="规划户型" align="center" prop="planningType" />
      <el-table-column label="物业公司" align="center" prop="propertyCompany" />
      <el-table-column
        label="物业费用/元/m2/月元/m2/月"
        align="center"
        prop="propertyExpenses"
      />
      <el-table-column label="供暖方式" align="center" prop="heatingMode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.plot_heating_mode"
            :value="scope.row.heatingMode"
          />
        </template>
      </el-table-column>
      <el-table-column label="房屋类型" align="center" prop="houseType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.plot_houses_type"
            :value="scope.row.houseType"
          />
        </template>
      </el-table-column>
      <el-table-column label="供水" align="center" prop="waterMode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_water_mode"
            :value="scope.row.waterMode"
          />
        </template>
      </el-table-column>
      <el-table-column label="供电" align="center" prop="electricMode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_electric_mode"
            :value="scope.row.electricMode"
          />
        </template>
      </el-table-column>
      <el-table-column label="燃气" align="center" prop="gasMode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_gas_mode"
            :value="scope.row.gasMode"
          />
        </template>
      </el-table-column>
      <el-table-column label="通讯配套齐备" align="center" prop="isKit">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_is_kit"
            :value="scope.row.isKit"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="小区特点"
        align="center"
        prop="cellCharacteristics"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['plot:plot:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['plot:plot:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改小区功能列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="小区名称" prop="communityName">
          <el-input v-model="form.communityName" placeholder="请输入小区名称" />
        </el-form-item>
        <el-form-item label="占地面积/m2" prop="floorArea">
          <el-input v-model="form.floorArea" placeholder="请输入占地面积/m2" />
        </el-form-item>
        <el-form-item label="建筑面积/m2" prop="structureArea">
          <el-input
            v-model="form.structureArea"
            placeholder="请输入建筑面积/m2"
          />
        </el-form-item>
        <el-form-item label="绿化面积/m2" prop="greenArea">
          <el-input v-model="form.greenArea" placeholder="请输入绿化面积/m2" />
        </el-form-item>
        <el-form-item label="绿化率/%" prop="greenRate">
          <el-input v-model="form.greenRate" placeholder="请输入绿化率/%" />
        </el-form-item>
        <el-form-item label="容积率" prop="plotRate">
          <el-input v-model="form.plotRate" placeholder="请输入容积率" />
        </el-form-item>
        <el-form-item label="规划车位" prop="plannedParking">
          <el-input
            v-model="form.plannedParking"
            placeholder="请输入规划车位"
          />
        </el-form-item>
        <el-form-item label="车位配比" prop="parkingRatio">
          <el-input v-model="form.parkingRatio" placeholder="请输入车位配比" />
        </el-form-item>
        <el-form-item label="规划楼栋" prop="plannedBuilding">
          <el-input
            v-model="form.plannedBuilding"
            placeholder="请输入规划楼栋"
          />
        </el-form-item>
        <el-form-item label="物业公司" prop="propertyCompany">
          <el-input
            v-model="form.propertyCompany"
            placeholder="请输入物业公司"
          />
        </el-form-item>
        <el-form-item label="物业费用/元/m2/月元/m2/月" prop="propertyExpenses">
          <el-input
            v-model="form.propertyExpenses"
            placeholder="请输入物业费用/元/m2/月元/m2/月"
          />
        </el-form-item>
        <el-form-item label="供暖方式" prop="heatingMode">
          <el-radio-group v-model="form.heatingMode">
            <el-radio
              v-for="dict in dict.type.plot_heating_mode"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="房屋类型" prop="houseType">
          <el-radio-group v-model="form.houseType">
            <el-radio
              v-for="dict in dict.type.plot_houses_type"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="供水" prop="waterMode">
          <el-radio-group v-model="form.waterMode">
            <el-radio
              v-for="dict in dict.type.houses_water_mode"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="供电" prop="electricMode">
          <el-radio-group v-model="form.electricMode">
            <el-radio
              v-for="dict in dict.type.houses_electric_mode"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="燃气" prop="gasMode">
          <el-radio-group v-model="form.gasMode">
            <el-radio
              v-for="dict in dict.type.houses_gas_mode"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="通讯配套齐备" prop="isKit">
          <el-radio-group v-model="form.isKit">
            <el-radio
              v-for="dict in dict.type.houses_is_kit"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="小区特点" prop="cellCharacteristics">
          <el-input
            v-model="form.cellCharacteristics"
            placeholder="请输入小区特点"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPlot,
  getPlot,
  delPlot,
  addPlot,
  updatePlot,
} from "@/api/plot/plot";

export default {
  name: "Plot",
  dicts: [
    "houses_water_mode",
    "houses_is_kit",
    "houses_gas_mode",
    "houses_electric_mode",
    "plot_houses_type",
    "plot_heating_mode",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小区功能列表表格数据
      plotList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        buildingId: null,
        communityName: null,
        floorArea: null,
        structureArea: null,
        greenArea: null,
        greenRate: null,
        plotRate: null,
        plannedParking: null,
        parkingRatio: null,
        plannedBuilding: null,
        planningType: null,
        propertyCompany: null,
        propertyExpenses: null,
        heatingMode: null,
        houseType: null,
        waterMode: null,
        electricMode: null,
        gasMode: null,
        isKit: null,
        cellCharacteristics: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询小区功能列表列表 */
    getList() {
      this.loading = true;
      listPlot(this.queryParams).then((response) => {
        this.plotList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        buildingId: null,
        communityName: null,
        floorArea: null,
        structureArea: null,
        greenArea: null,
        greenRate: null,
        plotRate: null,
        plannedParking: null,
        parkingRatio: null,
        plannedBuilding: null,
        planningType: null,
        propertyCompany: null,
        propertyExpenses: null,
        heatingMode: null,
        houseType: null,
        waterMode: null,
        electricMode: null,
        gasMode: null,
        isKit: null,
        cellCharacteristics: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加小区功能列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPlot(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改小区功能列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatePlot(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlot(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除小区功能列表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delPlot(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "plot/plot/export",
        {
          ...this.queryParams,
        },
        `plot_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
